package com.yb0os1.adapter.reids2etcd.etcd;

import io.etcd.jetcd.ByteSequence;
import io.etcd.jetcd.Client;
import io.etcd.jetcd.kv.GetResponse;

import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;

/***
 * 这个是etcd的测试类
 */
public class EtcdTest {
    public static void main(String[] args) throws Exception {
        Client build = Client.builder().endpoints("http://192.168.150.150:2379").build();
        ByteSequence key = ByteSequence.from("yb0os1", StandardCharsets.UTF_8);
        CompletableFuture<GetResponse> getResponse = build.getKVClient().get(key);
        GetResponse response = getResponse.get();
        if (response.getCount() > 0){
            System.out.println(response.getKvs().get(0).getValue().toString(StandardCharsets.UTF_8));
        }else{
            System.out.println("没有数据");
        }

//        ByteSequence value = ByteSequence.from("yb0os1", StandardCharsets.UTF_8);
//        CompletableFuture<PutResponse> put = build.getKVClient().put(key, value);
//        PutResponse putResponse = put.get();
//        System.out.println(putResponse);

//        getResponse = build.getKVClient().get(key);
//        response = getResponse.get();
//        if (response.getCount() > 0){
//            System.out.println(response.getKvs().get(0).getValue());
//        }else{
//            System.out.println("没有数据");
//        }
    }
}
